package com.baizhi.controller.v2;

import com.baizhi.entity.Pet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController("petControllerV2")
@RequestMapping("/v2/pets")
public class PetController {
    private static final Logger logger = LoggerFactory.getLogger(PetController.class);

    /**
     * 查询宠物信息
     */
    @GetMapping("/{id}")
    public ResponseEntity<Pet> pet(@PathVariable Integer id) {
        logger.debug("查询id：{}", id);
        Pet pet = new Pet(id, "小红帽", 23);
        return new ResponseEntity<>(pet, HttpStatus.OK);
    }

    /**
     * 查询宠物列表
     */
    @GetMapping
    public ResponseEntity<List<Pet>> pets() {
        List<Pet> list = new ArrayList<>();
        list.add(new Pet(21, "小红帽", 23));
        list.add(new Pet(24, "小猪", 22));
        return new ResponseEntity<>(list, HttpStatus.OK);
    }

    /**
     * 添加宠物
     */
    @PostMapping
    public ResponseEntity<Void> save(@RequestBody Pet pet) {
        logger.debug("添加宠物：{}", pet);
        // 调用业务方法
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /**
     * 更新宠物
     */
    @PutMapping("/{id}")
    public ResponseEntity<Void> update(@PathVariable Integer id, @RequestBody Pet pet) {
        logger.debug("更新id：{}", id);
        logger.debug("更新宠物：{}", pet);
        // 调用业务方法
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /**
     * 删除宠物
     */
    @DeleteMapping("/{id}")
    public ResponseEntity<Void> delete(@PathVariable Integer id) {
        logger.debug("删除id：{}", id);
        // 调用业务方法
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
